<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
<script type="module">
    import {AjaxPromise} from "../js/ajax.js";


    // 依次按属性发送请求 => 等第一个完成之后,在启动第二个 => 后面的请求可以依赖于前面的结果
    // T = T1 + T2 + T3;

   /*  var p1 = AjaxPromise({
        url:"../data/1.txt",
    })
    var str = "";
    p1.then(function(txt){
        console.log(txt);
        str += txt;
        var p2 = AjaxPromise({
            url:"../data/2.txt",
        })
        return p2;
    }).then(function(txt){
        console.log(txt);
        str += txt;
        
        var p3 = AjaxPromise({
            url:"../data/3.txt",
        })
        return p3;
    }).then(function(txt){
        console.log(txt);
        str += txt;

        console.log("str:",str);

    }).catch(function(err){
        console.log("reject",err);
    }) */

    // 同时发送请求 => 依次返回结果   => 适用于多请求同时发送,每个请求都是独立的,且按顺序返回结果
    // T = (T1 , T2 , T3 中最慢的)

    var p1 = AjaxPromise({
        url:"../data/1.txt",
    })
    var p2 = AjaxPromise({
        url:"../data/2.txt",
    })
    var p3 = AjaxPromise({
        url:"../data/3.txt",
    })

    p1.then(function(arg){
        console.log("fulfilled",arg);
        return p2;
    }).then(function(arg){
        console.log("fulfilled",arg);
        return p3;
    }).then(function(arg){
        console.log("fulfilled",arg);
    }).catch(function(err){
        console.log("rejected",err);
    })



</script>
</html>